1 2 3 4 5 6 7 8 9 10 11 12
| class Solution(object): level_true = 0 def preorder(self, root, level, level_true): if root: if level_true < level+1: print(level_true) self.level_true += 1 self.preorder(root.left, level+1, self.level_true) self.preorder(root.right, level+1, self.level_true) def maxDepth(self, root): self.preorder(root, 0, self.level_true) return self.level_true
|